package com.xzavier.yunlian_interview.controller;

import com.xzavier.yunlian_interview.service.ex.*;
import com.xzavier.yunlian_interview.utils.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;

public class BaseController {
    @ExceptionHandler({BaseException.class})
    public JsonResult<Void> handleBaseController(Throwable e) {
        JsonResult<Void> result = new JsonResult<>();
        if (e instanceof LoginException) {
            result.setCode(401);
            result.setMessage(e.getMessage());
        }
        if (e instanceof ClockResException) {
            result.setCode(403);
            result.setMessage(e.getMessage());
        }
        if (e instanceof FileException) {
            result.setCode(405);
            result.setMessage(e.getMessage());
        }
        if (e instanceof QuestionRecordException) {
            result.setCode(406);
            result.setMessage(e.getMessage());
        }
        if (e instanceof RegisterException) {
            result.setCode(403);
            result.setMessage(e.getMessage());
        }
        if (e instanceof StudyDurationException) {
            result.setCode(407);
            result.setMessage(e.getMessage());
        }
        return result;
    }
}
